package com.hand.wyc24548.infra.repository.impl;

import java.util.List;

import org.apache.commons.collections4.CollectionUtils;
import org.hzero.mybatis.base.impl.BaseRepositoryImpl;
import org.springframework.stereotype.Component;

import com.hand.wyc24548.domain.entity.Company;
import com.hand.wyc24548.domain.repository.CompanyRepository;
import com.hand.wyc24548.infra.mapper.CompanyMapper;

import io.choerodon.core.domain.Page;
import io.choerodon.mybatis.pagehelper.PageHelper;
import io.choerodon.mybatis.pagehelper.domain.PageRequest;

/**
 * @Author wangyc
 * @create 2019/8/5 19:36
 */

@Component
public class CompanyRepositoryImpl extends BaseRepositoryImpl<Company> implements CompanyRepository {

    private final CompanyMapper companyMapper;

    public CompanyRepositoryImpl(CompanyMapper companyMapper) {
        this.companyMapper = companyMapper;
    }

    @Override
    public Page<Company> selectCompany(Company company, PageRequest pageRequest) {
        return PageHelper.doPage(pageRequest,() -> companyMapper.selectCompany(company));
    }

    @Override
    public Company selectDetailByCompanyNumber(String companyNumber) {
        Company company=new Company();
        company.setCompanyNumber(companyNumber);
        List<Company> companies=companyMapper.selectCompany(company);
        return CollectionUtils.isNotEmpty(companies) ? companies.get(0):null;
    }
}
